package com.framework.buss.ai.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.framework.buss.ai.model.Question;
import com.framework.buss.ai.params.QuestionParam;
import com.framework.buss.ai.service.IQuestionService;
import com.framework.buss.ai.vo.QuestionVO;
import com.framework.common.domain.ParamPage;
import com.framework.common.domain.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangzhg
 */
@RestController
@RequestMapping("/question")
@Api(value = "question", tags = "预置问题")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @ApiOperation("获取列表接口")
    @GetMapping("list")
    public ResultData list(QuestionParam param, ParamPage paramPage) {
        Page page = Page.of(paramPage.getPageNo(), paramPage.getPageSize());
        IPage<QuestionVO> list = questionService.list(param, page);
        return ResultData.data(list);
    }

    @ApiOperation("获取单个")
    @GetMapping("one/{id}")
    public ResultData getOne(@PathVariable("id") String id) {
        Question item = questionService.getOne(id);
        return ResultData.data(item);
    }

    @ApiOperation(value = "保存")
    @PostMapping(value = "/save")
    public ResultData save(@RequestBody Question param) {
        String id = questionService.save(param);
        return ResultData.success(id);
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/del")
    public ResultData del(@RequestBody List<String> ids) {
        questionService.del(ids);
        return ResultData.success();
    }
}
